<template>
  <Container>
    <Tabs v-model="tab">
      <div slot="extra">
        <Button
          size="large"
          class="item"
          type="primary"
          @click="onBatch('integral')">批量奖惩积分</Button>
        <Button
          size="large"
          class="item"
          @click="onBatch('rebate')">批量奖惩返利</Button>
      </div>
      <TabPane label="批量奖惩积分返利" name="tab1">
         <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
        />
      </TabPane>
    </Tabs>
  </Container>
</template>
<script>
import BatchListData from './list/BatchListData'
import homeTable from '@/components/homeTable'
export default {
  name: 'welfare/batch/list',
  components: {
    homeTable
  },
  data() {
    return {
      tab: "tab1",
      list: BatchListData
    };
  },
  mounted() {
    this.getData();
    this.$bus.$on('onLook', ({rewardType, sourceOrderId}) => {this.onLook(rewardType, sourceOrderId)})
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    onLook(rewardType, sourceOrderId) { // 1积分 2返利
      this.$router.push({
        name: rewardType === 1 ? 'welfare/integralaudit/list' : 'welfare/rebateaudit/list',
        query: {
          sourceOrderId,
          currentPage: 1
        }
      })
    },
    getData() {
      this.list.status = "loading"
      this.$ajaxGet("/assets/store_reward/batch/page").then(data => {
        this.list.data = [];
        this.list.totalItem = Number(data.total)
        this.list.data = data.records || []
        this.list.status = "pass"
      }).catch(() => {
        this.list.status = "error"
      })
    },
    onBatch(type) {
      this.$router.push({
        name: `welfare/batch/${type}`
      })
    },
    onPageChange(number) {
      this.list.currentPage = number
      this.getData()
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.getData()
    }
  }
};
</script>
